package com.blog.dao.impl;

import com.blog.dao.LoginDao;
import com.blog.pojo.User;
import com.blog.util.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class LoginDaoImpl implements LoginDao {
    private QueryRunner queryRunner = new QueryRunner( DruidUtils.getDataSource());
    @Override
    public User findByUserName(String userName) {
        String sql="SELECT * FROM users WHERE username= ? ";
        Object[] params={userName};
        try {
            User user =  queryRunner.query(sql,new BeanHandler<User>( User.class), params);
            return user;
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }






}
